package cn.com.bluemoon.daps.common.toolkit;


import cn.com.bluemoon.daps.common.exception.DapThrowException;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @author Jarod.Kong
 * @date 2020/12/18 11:40
 */
public class BmBeanUtils {
    private BmBeanUtils(){}

    public static <T> T mapToBean(Map<String, Object> map, Class<T> clazz) {
        T bean = ClassUtils.newInstance(clazz);
        try {
            BeanUtils.populate(bean, map);
        } catch (IllegalAccessException | InvocationTargetException e) {
            throw new DapThrowException("转换异常");
        }
        return bean;
    }
}
